import React, { Component } from "react";
import RouterApp from "./router/RouterApp";
import { connect } from "react-redux";
class App extends Component {
  constructor(props) {
    super(props);
    this.state = {};
  }
  componentDidMount() {
    let cityName = window.localStorage.getItem("cityName") || "武汉";
    this.props.initCity(cityName);
  }
  render() {
    // console.log(this.props);
    return (
      <div>
        {/* <h2>App</h2>
        <span className="iconfont icon-team"></span> */}
        <RouterApp />
      </div>
    );
  }
}
function mapStateToProps(state, props) {
  console.log(state);
  return {
    ...state,
  };
}
// initCity如果执行了 那么就会触发 dispatch()
// App组件 一加载的时候就调用初始化initCity
function mapDispatchToProps(dispatch) {
  return {
    initCity: (cityName) =>
      dispatch({
        type: "init_city",
        city: cityName,
      }),
  };
}
export default connect(mapStateToProps, mapDispatchToProps)(App);
